package com.ccc3gc.listener;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.Date;

@WebListener
public class SessionListener implements HttpSessionListener {
    @Override
    public void sessionCreated(HttpSessionEvent se) {
        String dateTime = new Date().toLocaleString();
        HttpSession session = se.getSession();
        System.out.println(dateTime + " 创建 session,ID：" + session.getId());

    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        String dateTime = new Date().toLocaleString();
        HttpSession session = se.getSession();
        System.out.println(dateTime + " 销毁 session,ID：" + session.getId());
    }
}
